Gamma

We can use the base plot functions in R to create a plot of the pdf for a gamma random variable \(X\) with variaous parameters \(\alpha\) and \(\beta\). Note that R defines \(\alpha = \mbox{shape}\) and \(\beta = \mbox{scale}\) — and scale = 1/rate.

  x <- seq(0, 10, by=0.001)
  plot(x, dgamma(x, shape=0.5, scale=0.5), lty=1, col=1, type="l", xlab="x", ylab="f(x)", ylim=c(0,1))
  lines(x, dgamma(x, shape=1, scale=0.5), lty=2, col=2)
  lines(x, dgamma(x, shape=2, scale=0.5), lty=3, col=3)
  lines(x, dgamma(x, shape=0.5, scale=1), lty=4, col=4)
  lines(x, dgamma(x, shape=1, scale=1), lty=5, col=5)
  lines(x, dgamma(x, shape=2, scale=1), lty=6, col=6)
  lines(x, dgamma(x, shape=0.5, scale=2), lty=7, col=7)
  lines(x, dgamma(x, shape=1, scale=2), lty=8, col=8)
  lines(x, dgamma(x, shape=2, scale=2), lty=9, col=9)

The CDF may be plotted analogously.

  x <- seq(0, 10, by=0.001)
  plot(x, pgamma(x, shape=0.5, scale=0.5), lty=1, col=1, type="l", xlab="x", ylab="F(x)")
  lines(x, pgamma(x, shape=1, scale=0.5), lty=2, col=2)
  lines(x, pgamma(x, shape=2, scale=0.5), lty=3, col=3)
  lines(x, pgamma(x, shape=0.5, scale=1), lty=4, col=4)
  lines(x, pgamma(x, shape=1, scale=1), lty=5, col=5)
  lines(x, pgamma(x, shape=2, scale=1), lty=6, col=6)
  lines(x, pgamma(x, shape=0.5, scale=2), lty=7, col=7)
  lines(x, pgamma(x, shape=1, scale=2), lty=8, col=8)
  lines(x, pgamma(x, shape=2, scale=2), lty=9, col=9)

Exponential

Recall that rate = 1/scale. This is equivalent to \(\lambda = \frac{1}{ \beta}\).

  x <- seq(0, 10, by=0.001)
  plot(x, dexp(x, rate=0.5), lty=1, col=1, type="l", xlab="x", ylab="f(x)", ylim=c(0,2))
  lines(x, dexp(x, rate=1), lty=2, col=2)
  lines(x, dexp(x, rate=2), lty=3, col=3)

  plot(x, pexp(x, rate=0.5), lty=1, col=1, type="l", xlab="x", ylab="F(x)")
  lines(x, pexp(x, rate=1), lty=2, col=2)
  lines(x, pexp(x, rate=2), lty=3, col=3)

Chi-Squared

The chi-squared distribution is dependent on the degrees of freedom.

  x <- seq(0, 10, by=0.001)
  plot(x, dchisq(x, df=1), lty=1, col=1, type="l", xlab="x", ylab="f(x)", ylim=c(0,2))
  lines(x, dchisq(x, df=2), lty=2, col=2)
  lines(x, dchisq(x, df=5), lty=3, col=3)

  plot(x, pchisq(x, df=1), lty=1, col=1, type="l", xlab="x", ylab="F(x)")
  lines(x, pchisq(x, df=2), lty=2, col=2)
  lines(x, pchisq(x, df=5), lty=3, col=3)